/**
 * @file     moveZeroes.js
 * @brief    [283. 移动零](https://leetcode.cn/problems/move-zeroes/description/)
 * @author   Zhu
 * @date     2023-02-12 14:44
 */

/**
 * 双指针，可以参考[27. 移除元素](https://leetcode-cn.com/problems/remove-element/)
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {
    let i = 0;
    for (let j = 0; j < nums.length; j++) {
        if (nums[j] !== 0) {
            swap(i, j);
            i++;
        }
    }

    function swap(i, j) {
        let temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
};
